import { message } from 'ant-design-vue';
import Clipboard from 'clipboard';

function clipboardSuccess(txt) {
    message.success(`${txt}复制成功`);
}

function clipboardError(txt) {
    message.error(`${txt}复制失败`);
}

export const handleClipboard = (text, event,txt='信息')=>{
    const clipboard = new Clipboard(event.target, {
        text: () => text
    });
    clipboard.on('success', () => {
        clipboardSuccess(txt);
        clipboard.destroy();
    });
    clipboard.on('error', () => {
        clipboardError(txt);
        clipboard.destroy();
    });
    clipboard.onClick(event);
}
